import pandas as pd
import numpy as np
from sklearn.metrics import mean_squared_error
from sklearn.svm import SVR, SVC
from pro_data import DataSets
from utils.utiils_perf import *
import time


# def svm_func_rg(data_train, data_test, label_train, label_test):
#     '''
#         使用SVM进行回归
#     :param data_train:
#     :param label_train:
#     :param data_test:
#     :param label_test:
#     :return:
#     '''
#
#     # train
#     clf = SVR(kernel="rbf", C=5)
#     clf.fit(X=data_train, y=label_train)
#
#     # val test
#     pred_val = clf.predict(X=data_test)
#     precision = mean_squared_error(y_true=label_test, y_pred=pred_val)
#     # print("precision: ", precision)
#
#     df_res = pd.DataFrame({
#         'true': label_test,
#         'pred': pred_val
#     })
#     df_res.to_csv("res1_cv.csv", index=False)


def svm_func(data_train, data_test, label_train):
    # train
    clf = SVC(kernel="rbf", C=5, class_weight='balanced')
    clf.fit(X=data_train, y=label_train)
    # test
    pred_test = clf.predict(X=data_test)

    return pred_test


if __name__ == "__main__":
    # data2_naca0012
    # path_x = "data2_naca0012/dv.csv"
    # path_y = "data2_naca0012/fc.csv"
    #
    # ds = DataSets(path_x=path_x,
    #               path_y=path_y,
    #               label_index=2,
    #               label_threshold=-0.16,
    #               test_proportion=0.99)
    # data_train, data_test, label_train, label_test = ds.split_train_test()
    #
    # svm_func_cl(data_train, data_test, label_train, label_test)

    # data_final2
    path_x = "../data/data_final2/dv.csv"
    path_y = "../data/data_final2/fc.csv"

    test_proportion = 0.8
    ds = DataSets(path_x=path_x,
                  path_y=path_y,
                  label_index=0,
                  label_threshold=0.6,
                  test_proportion=test_proportion)

    loop_cls(ds, svm_func)
